﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdminDashboard.aspx.cs" Inherits="Secondhand_Book_Trade.AdminDashboard" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>管理后台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
    <style>
        h3 { margin-top: 40px; }
        .table { margin-bottom: 30px; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <table class="info-table">
                <tr>
                    <td>用户名：</td>
                    <td><asp:Label ID="lblUsername" runat="server" /></td>
                </tr>
                <tr>
                    <td>昵称：</td>
                    <td><asp:Label ID="lblNickname" runat="server" /></td>
                </tr>
                <tr>
                    <td>角色：</td>
                    <td><asp:Label ID="lblRole" runat="server" /></td>
                </tr>
                <tr>
                    <td>头像：</td>
                    <td><asp:Image ID="imgAvatar" runat="server" Width="80px" Height="80px" /></td>
                </tr>
                <tr>
                    <td>Email：</td>
                    <td><asp:Label ID="lblEmail" runat="server" /></td>
                </tr>
                <tr>
                    <td>手机：</td>
                    <td><asp:Label ID="lblPhone" runat="server" /></td>
                </tr>
            </table>
           <!-- 用户管理 -->
            <h3>用户管理</h3>
            <asp:GridView ID="gvUsers" runat="server" DataSourceID="SqlDataSourceUsers"
                AutoGenerateColumns="False" DataKeyNames="UserID"
                AllowPaging="true" PageSize="10"
                AllowSorting="true"
                CssClass="table table-bordered">
                <Columns>
                    <asp:BoundField DataField="UserID" HeaderText="ID" ReadOnly="True" />
                    <asp:BoundField DataField="Username" HeaderText="用户名" />
                    <asp:BoundField DataField="Nickname" HeaderText="昵称" />
                    <asp:BoundField DataField="Role" HeaderText="角色" />
                    <asp:BoundField DataField="Email" HeaderText="邮箱" />
                    <asp:BoundField DataField="Phone" HeaderText="手机" />
                    <asp:BoundField DataField="Gender" HeaderText="性别" />
                    <asp:BoundField DataField="AvatarUrl" HeaderText="头像URL" />
                    <asp:TemplateField HeaderText="头像">
                        <ItemTemplate>
                            <img src='<%# Eval("AvatarUrl") %>' width="40" height="40" style="border-radius:8px;" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
                </Columns>
            </asp:GridView>
            <asp:DetailsView ID="dvInsertUser" runat="server" DataSourceID="SqlDataSourceUsers"
                DefaultMode="Insert" AutoGenerateRows="False" CssClass="table table-bordered">
                <Fields>
                    <asp:BoundField DataField="Username" HeaderText="用户名" />
                    <asp:BoundField DataField="Password" HeaderText="密码" />
                    <asp:BoundField DataField="Role" HeaderText="角色" />
                    <asp:BoundField DataField="Email" HeaderText="邮箱" />
                    <asp:BoundField DataField="Phone" HeaderText="手机" />
                    <asp:BoundField DataField="Gender" HeaderText="性别" />
                    <asp:BoundField DataField="Nickname" HeaderText="昵称" />
                    <asp:BoundField DataField="AvatarUrl" HeaderText="头像URL" />
                    <asp:CommandField ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>
            <asp:SqlDataSource ID="SqlDataSourceUsers" runat="server"
                ConnectionString="<%$ ConnectionStrings:Secondhand_book_tradeConnectionString %>"
                SelectCommand="SELECT UserID, Username, Nickname, Role, Email, Phone, Gender, AvatarUrl FROM Users"
                InsertCommand="INSERT INTO Users (Username, Password, Role, Email, Phone, Gender, Nickname, AvatarUrl) VALUES (@Username, @Password, @Role, @Email, @Phone, @Gender, @Nickname, @AvatarUrl)"
                UpdateCommand="UPDATE Users SET Username=@Username, Role=@Role, Email=@Email, Phone=@Phone, Gender=@Gender, Nickname=@Nickname, AvatarUrl=@AvatarUrl WHERE UserID=@UserID"
                DeleteCommand="DELETE FROM Users WHERE UserID=@UserID">
                <InsertParameters>
                    <asp:Parameter Name="Username" Type="String" />
                    <asp:Parameter Name="Password" Type="String" />
                    <asp:Parameter Name="Role" Type="Int32" />
                    <asp:Parameter Name="Email" Type="String" />
                    <asp:Parameter Name="Phone" Type="String" />
                    <asp:Parameter Name="Gender" Type="String" />
                    <asp:Parameter Name="Nickname" Type="String" />
                    <asp:Parameter Name="AvatarUrl" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Username" Type="String" />
                    <asp:Parameter Name="Role" Type="Int32" />
                    <asp:Parameter Name="Email" Type="String" />
                    <asp:Parameter Name="Phone" Type="String" />
                    <asp:Parameter Name="Gender" Type="String" />
                    <asp:Parameter Name="Nickname" Type="String" />
                    <asp:Parameter Name="AvatarUrl" Type="String" />
                    <asp:Parameter Name="UserID" Type="Int32" />
                </UpdateParameters>
                <DeleteParameters>
                    <asp:Parameter Name="UserID" Type="Int32" />
                </DeleteParameters>
            </asp:SqlDataSource>

            <!-- 书籍管理 -->
            <h3>书籍管理</h3>
            <asp:GridView ID="gvBooks" runat="server" DataSourceID="SqlDataSourceBooks"
                AutoGenerateColumns="False" DataKeyNames="BookID"
                AllowPaging="true" PageSize="10"
                AllowSorting="true"
                CssClass="table table-bordered">
                <Columns>
                    <asp:BoundField DataField="BookID" HeaderText="ID" ReadOnly="True" />
                    <asp:BoundField DataField="SellerID" HeaderText="卖家ID" />
                    <asp:BoundField DataField="Title" HeaderText="书名" />
                    <asp:BoundField DataField="Author" HeaderText="作者" />
                    <asp:BoundField DataField="Price" HeaderText="价格" />
                    <asp:BoundField DataField="CategoryID" HeaderText="分类ID" />
                    <asp:BoundField DataField="Status" HeaderText="状态" />
                    <asp:BoundField DataField="CoverUrl" HeaderText="封面URL" />
                    <asp:TemplateField HeaderText="封面">
                        <ItemTemplate>
                            <img src='<%# Eval("CoverUrl") %>' width="40" height="50" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Description" HeaderText="简介" />
                    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
                </Columns>
            </asp:GridView>
            <asp:DetailsView ID="dvInsertBook" runat="server" DataSourceID="SqlDataSourceBooks"
                DefaultMode="Insert" AutoGenerateRows="False" CssClass="table table-bordered">
                <Fields>
                    <asp:BoundField DataField="SellerID" HeaderText="卖家ID" />
                    <asp:BoundField DataField="Title" HeaderText="书名" />
                    <asp:BoundField DataField="Author" HeaderText="作者" />
                    <asp:BoundField DataField="Price" HeaderText="价格" />
                    <asp:BoundField DataField="CategoryID" HeaderText="分类ID" />
                    <asp:BoundField DataField="Status" HeaderText="状态" />
                    <asp:BoundField DataField="CoverUrl" HeaderText="封面URL" />
                    <asp:BoundField DataField="Description" HeaderText="简介" />
                    <asp:CommandField ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>
            <asp:SqlDataSource ID="SqlDataSourceBooks" runat="server"
                ConnectionString="<%$ ConnectionStrings:Secondhand_book_tradeConnectionString %>"
                SelectCommand="SELECT BookID, SellerID, Title, Author, Price, CategoryID, Status, CoverUrl, Description FROM Books"
                InsertCommand="INSERT INTO Books (SellerID, Title, Author, Price, CategoryID, Status, CoverUrl, Description) VALUES (@SellerID, @Title, @Author, @Price, @CategoryID, @Status, @CoverUrl, @Description)"
                UpdateCommand="UPDATE Books SET SellerID=@SellerID, Title=@Title, Author=@Author, Price=@Price, CategoryID=@CategoryID, Status=@Status, CoverUrl=@CoverUrl, Description=@Description WHERE BookID=@BookID"
                DeleteCommand="DELETE FROM Books WHERE BookID=@BookID">
                <InsertParameters>
                    <asp:Parameter Name="SellerID" Type="Int32" />
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Author" Type="String" />
                    <asp:Parameter Name="Price" Type="Decimal" />
                    <asp:Parameter Name="CategoryID" Type="Int32" />
                    <asp:Parameter Name="Status" Type="Int32" />
                    <asp:Parameter Name="CoverUrl" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="SellerID" Type="Int32" />
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Author" Type="String" />
                    <asp:Parameter Name="Price" Type="Decimal" />
                    <asp:Parameter Name="CategoryID" Type="Int32" />
                    <asp:Parameter Name="Status" Type="Int32" />
                    <asp:Parameter Name="CoverUrl" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="BookID" Type="Int32" />
                </UpdateParameters>
                <DeleteParameters>
                    <asp:Parameter Name="BookID" Type="Int32" />
                </DeleteParameters>
            </asp:SqlDataSource>

            <!-- 订单管理 -->
            <h3>订单管理</h3>
            <asp:GridView ID="gvOrders" runat="server" DataSourceID="SqlDataSourceOrders"
                AutoGenerateColumns="False" DataKeyNames="OrderID"
                AllowPaging="true" PageSize="10"
                AllowSorting="true"
                CssClass="table table-bordered">
                <Columns>
                    <asp:BoundField DataField="OrderID" HeaderText="订单ID" ReadOnly="True" />
                    <asp:BoundField DataField="BuyerID" HeaderText="买家ID" />
                    <asp:BoundField DataField="BookID" HeaderText="书籍ID" />
                    <asp:BoundField DataField="Quantity" HeaderText="数量" />
                    <asp:BoundField DataField="TotalAmount" HeaderText="总金额" />
                    <asp:BoundField DataField="Status" HeaderText="状态" />
                    <asp:BoundField DataField="CreatedAt" HeaderText="下单时间" />
                    <asp:BoundField DataField="ShippingAddressID" HeaderText="收货地址ID" />
                    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
                </Columns>
            </asp:GridView>
            <asp:DetailsView ID="dvInsertOrder" runat="server" DataSourceID="SqlDataSourceOrders"
                DefaultMode="Insert" AutoGenerateRows="False" CssClass="table table-bordered">
                <Fields>
                    <asp:BoundField DataField="BuyerID" HeaderText="买家ID" />
                    <asp:BoundField DataField="BookID" HeaderText="书籍ID" />
                    <asp:BoundField DataField="Quantity" HeaderText="数量" />
                    <asp:BoundField DataField="TotalAmount" HeaderText="总金额" />
                    <asp:BoundField DataField="Status" HeaderText="状态" />
                    <asp:BoundField DataField="ShippingAddressID" HeaderText="收货地址ID" />
                    <asp:CommandField ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>
            <asp:SqlDataSource ID="SqlDataSourceOrders" runat="server"
                ConnectionString="<%$ ConnectionStrings:Secondhand_book_tradeConnectionString %>"
                SelectCommand="SELECT OrderID, BuyerID, BookID, Quantity, TotalAmount, Status, CreatedAt, ShippingAddressID FROM Orders"
                InsertCommand="INSERT INTO Orders (BuyerID, BookID, Quantity, TotalAmount, Status, ShippingAddressID) VALUES (@BuyerID, @BookID, @Quantity, @TotalAmount, @Status, @ShippingAddressID)"
                UpdateCommand="UPDATE Orders SET BuyerID=@BuyerID, BookID=@BookID, Quantity=@Quantity, TotalAmount=@TotalAmount, Status=@Status, ShippingAddressID=@ShippingAddressID WHERE OrderID=@OrderID"
                DeleteCommand="DELETE FROM Orders WHERE OrderID=@OrderID">
                <InsertParameters>
                    <asp:Parameter Name="BuyerID" Type="Int32" />
                    <asp:Parameter Name="BookID" Type="Int32" />
                    <asp:Parameter Name="Quantity" Type="Int32" />
                    <asp:Parameter Name="TotalAmount" Type="Decimal" />
                    <asp:Parameter Name="Status" Type="Int32" />
                    <asp:Parameter Name="ShippingAddressID" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="BuyerID" Type="Int32" />
                    <asp:Parameter Name="BookID" Type="Int32" />
                    <asp:Parameter Name="Quantity" Type="Int32" />
                    <asp:Parameter Name="TotalAmount" Type="Decimal" />
                    <asp:Parameter Name="Status" Type="Int32" />
                    <asp:Parameter Name="ShippingAddressID" Type="Int32" />
                    <asp:Parameter Name="OrderID" Type="Int32" />
                </UpdateParameters>
                <DeleteParameters>
                    <asp:Parameter Name="OrderID" Type="Int32" />
                </DeleteParameters>
            </asp:SqlDataSource>
        </div>
    </form>
</body>
</html>
